# coding=utf-8

# from selenium import webdriver
# import logging
# #
# from selenium.webdriver.common.by import By
# #
# logging.basicConfig(level=logging.DEBUG)  # 打印源码中的日志
# dr = webdriver.Chrome() # 打开浏览器
# dr.get("https://www.baidu.com") # 访问我的博客首页
# dr.find_element(By.XPATH,'//*[@id="su"]').click()
import time

import requests
#
# # 请求地址(打开浏览器)
driver_url = 'http://localhost:9515/session'
# # 打开浏览器的请求参数
driver_value = {"capabilities":
                    {"firstMatch": [{}],
                     "alwaysMatch":
                         {"browserName":
                              "chrome",
                          "platformName": "any",
                          "goog:chromeOptions":
                              {"extensions": [], "args": []}}},
                "desiredCapabilities":
                    {"browserName":
                         "chrome",
                     "version": "",
                     "platform": "ANY",
                     "goog:chromeOptions": {"extensions": [],
                                            "args": []}}}
# 发送求清
response_session = requests.post(driver_url, json=driver_value)
res  = response_session.json()
print(res)
# print(type(res))
# 访问我的博客的请求地址 （这个地址是我们上面记录的地址）
url = 'http://localhost:9515/session/' + res.get("value").get("sessionId") + '/url'
# # 访问我的博客的请求参数
value = {"url": "https://www.baidu.com", "sessionId": res.get("value").get("sessionId")}
response_blog = requests.post(url=url, json=value)

url =   'http://localhost:9515/session/' +  res.get("value").get("sessionId") + '/element'
value = {"using": "xpath", "value": "//*[@id=\"su\"]"}
res1 = requests.post(url=url,json=value)
print(res1.json())
print(res1.json().get("value").get("element-6066-11e4-a52e-4f735466cecf"))

time.sleep(5)
url = 'http://localhost:9515/session/' +  res.get("value").get("sessionId") +"/element/" +res1.json().get("value").get("element-6066-11e4-a52e-4f735466cecf")+'/click'
value = {"id": res1.json().get("value").get("element-6066-11e4-a52e-4f735466cecf")}
res2 = requests.post(url=url,json=value)
print(res2)

# DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:1894/session/c7e9c071a6e720f3eddbe36db4ad1827/element/F6DDC3AFA42C2963AF24EB5EEC2A7FD2_element_5/click {"id": "F6DDC3AFA42C2963AF24EB5EEC2A7FD2_element_5"}
# DEBUG:urllib3.connectionpool:http://127.0.0.1:1894 "POST /session/c7e9c071a6e720f3eddbe36db4ad1827/element/F6DDC3AFA42C2963AF24EB5EEC2A7FD2_element_5/click HTTP/1.1" 200 14
# DEBUG:selenium.webdriver.remote.remote_connection:Finished Request